﻿package com.teaphy.coroutinecrawler.job

import kotlinx.coroutines.*
import java.lang.Exception

fun main() = runBlocking {
//    val coroutineExceptionHandler = CoroutineExceptionHandler { context, exception ->
//        println("coroutineExceptionHandler context: $context, exception: $exception")
//    }
    println("runBlocking --> start")
    with(CoroutineScope(context = SupervisorJob())) {
        println("SupervisorJob --> start")
        launch(context = CoroutineName("CoroutineA")) {
            println("CoroutineA --> start")
            delay(1000)

            throw Exception("test Exception")

            println("CoroutineA --> end")
        }

        launch(context = CoroutineName("CoroutineB")) {
            println("CoroutineB --> start")
            delay(2000)

            throw Exception("test Exception")

            println("CoroutineB --> end")
        }

        delay(3000)

        println("SupervisorJob --> end")
    }

    delay(5000)

    println("runBlocking --> end")
}